<?php

namespace HelloAdmin\Controller;


class CateController extends CommonController {

    private $Cate;

    public function __construct() {
        parent::__construct();
        $this->Cate = new \Common\Model\BookCateModel();
    }

    public function index() {

        $this->display('Book/cate');
    }

    public function add(){


        $this->display('Book/addCate');
    }

    public function insert(){
        $post = $this->GetParam('number,cart_id,brand,mobile,age,color,image_id,vin_num,ascription,remark');
        $data['number'] = $post['number'];
        $data['brand'] = $post['brand'];
        $data['mobile'] = $post['mobile'];
        $data['age'] = $post['age'];
        $data['color'] = $post['color'];
        $data['image_id'] = $post['image_id'];
        $data['vin_num'] = $post['vin_num'];
        $data['ascription'] = $post['ascription'];
        $data['create_time'] = time();
        $data['ascription'] = $post['ascription'];


        if($this->Cate->SaveData($data)){
            $this->success('添加成功');
        }
        $this->error('添加失败');
    }

    public function updateAlias(){
        $cate_id = I('post.cate_id');
        $alias = I('post.alias');
        if(empty($alias) || empty($cate_id)){
            return FALSE;
        }
        if($this->Cate->updateAlias($cate_id,$alias)){
            echo 'success';exit();
        }
        return 'FALSE';
    }

    public function coverImg() {
        $config = array(
            'maxSize' => 20000000, //上传的文件大小限制 (0-不做限制)
            'savePath' => '/Cate/', //保存路径
            'autoSub' => true,
        );
        $res = $this->UploadImg($config);

        exit(json_encode($res));
    }

    public function updateOneField(){
        if($this->Cate->updateField()){
            echo 'success';exit;
        }
    }

    public function getList(){
        $data = $this->Cate->getList();
        echo (json_encode($data));
    }

}
